package self.niu.com.resume.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import self.niu.com.resume.AppBase;
import self.niu.com.resume.R;
import self.niu.com.resume.ui.ProgressUtils;

/**
 * A simple {@link Fragment} subclass.
 */
public class JobFragment extends Fragment {
    private View view;
    @ViewInject(R.id.job_mes_wbv)
    private WebView web;

    public static JobFragment getInstance() {
        return new JobFragment();
    }

    public JobFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_job, container, false);
        ProgressUtils.getInstances().showProgress(getActivity());
        ViewUtils.inject(this, view);
        initView();
        return view;

    }

    private void initView() {
        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl("http://blog.csdn.net/u010714000/article/details/48804951");
        web.setWebViewClient(new HelloWebViewClient());
        web.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress == 100) {
                    ProgressUtils.getInstances().hideProgress();
                }
            }
        });
    }

    //Web视图
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
}
